package com.xiaotu.dao;

import com.xiaotu.model.StarModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;

/**
 * @author 王艳龙
 * @create 2021-07-13 14:05
 */
public interface StarDao extends BaseMapper<StarModel> {

    @Select("<script>"
            + " SELECT tt.alias FROM "
            + "   (SELECT "
            + "     (CASE WHEN t2.starid IS NULL THEN '0' "
            + "     WHEN t2.starid IS NOT NULL THEN '1' ELSE '2' END) AS star_up, "
            + "     (CASE WHEN t22.starid IS NULL THEN '0' "
            + "     WHEN t22.starid IS NOT NULL THEN '1' ELSE '2' END) AS ex_up,t1.* "
            + "  FROM "
            + "  basicinfo.tab_star_info t1 "
            + "  LEFT JOIN basicinfo.tab_star_info_to_tencent_exception t2 ON t1.starid = t2.starid "
            + "  LEFT JOIN basicinfo.tab_star_exception_info t22 ON t1.starid=t22.starid "
            + "  WHERE t1.foreignersign=0 "
            + "  AND t1.name!~* '^[a-z]' "
            + "    ) tt "
            + "  LEFT JOIN basicinfo.tab_star_delete_record t3 ON tt.starid = t3.starid "
            + "  WHERE "
            + "  t3.starid IS NULL "
            + "<if test='updateDate !=null and updateDate !=null "
            + "and updateDate !=\"\" and updateDate !=\"\" '>"
            + "     AND tt.lastupdatetime::date='${updateDate}' "
            + "</if>"
            + "  ORDER BY tt.starid "
            + "<if test='page !=null and rows !=null "
            + " and page !=\"\" and rows !=\"\" '>"
            + "     LIMIT #{rows} OFFSET #{rows}*(#{page}-1) "
            + "</if>"
            + "</script>")
    //获取艺人信息记录
    List<StarModel> getListStar(@Param("updateDate") String updateDate, @Param("page") Integer page, @Param("rows") Integer rows);

}
